import { cpuInfo, cpuLoadInfo, contentStyle } from './cpu'
import { allDisks } from './disk'
import { getMemInf } from './mem'
import { batteryInfo } from './battery'
import SysUtil from './utils/SysUtil'
import { netInfo } from './network'

const allData = {
  cpu: null,
  cpuLoadInf: null,
  contentStyle,
  memBaseInf: null,
  batteryInf: null,
  disks: {},
  netInf: null,
  runningTime: 0
}

cpuInfo().then((data) => {
  allData.cpu = data
})

setInterval(() => {
  allData.runningTime = SysUtil.timeInfo().runningTime
}, 1000)

setInterval(
  (function target() {
    batteryInfo().then((data) => {
      allData.batteryInf = data
    })

    cpuLoadInfo().then((data) => {
      allData.cpuLoadInf = data
    })

    getMemInf().then((baseInfo) => {
      allData.memBaseInf = baseInfo
    })

    return target
  })(),
  3000
)

setTimeout(() => {
  setInterval(
    (function target() {
      netInfo().then((res) => {
        allData.netInf = res
      })

      allDisks().then((data) => {
        allData.disks = data
      })

      return target
    })(),
    2000
  )
}, 500)

const getData = () => {
  return allData
}

export { getData }
